;(function(){
  'use strict';
  angular.module('controllers.accessSystem.auditDetails')
  .controller('failureTnAtRsController',failureTnAtRsController);
  function failureTnAtRsController($scope,$mdDialog,failureTransactionAuditRecordsService,CoreService,CoreLoading){
    $scope.flag = {
      state: true,
      arrow: false,
    };
    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth();
    var day = date.getDate();
    var hour=date.getHours();
    var minute=date.getMinutes();
    $scope.send = {};
    //页面查询项绑定对象
    $scope.params = {
      startTime: new Date(year,month,day,0,0),
      endTime: new Date(year,month,day,0,0)
    };

    //查询
    $scope.search = function(){
      $scope.flag.state = !$scope.flag.state;
      if(!$scope.flag.state){
        $scope.send = {
          startTime : $scope.params.startTime,
          endTime : $scope.params.endTime,
          reviewer : $scope.params.reviewer
        };
        $scope.send.startTime = CoreService.dateFormat($scope.params.startTime, 'yyyy-MM-dd hh:mm');
        $scope.send.endTime = CoreService.dateFormat($scope.params.endTime, 'yyyy-MM-dd hh:mm');
        failureTransactionAuditRecordsService.query($scope.send,function(res){
        if(res.state === '10000' && res.data.length >= 1){
          $scope.items = res.data;
          $scope.flag.arrow = true;
        }else if(res.data.length === 0){
            flag.state = true;
            flag.arrow = false;
            CoreService.dialog('查询无数据');
        }else {
            flag.state = true;
            flag.arrow = false;
            CoreService.dialog('查询错误');
        }
        CoreLoading.setState(false);
      });
    }
    };


    $scope.itemss = {};
    $scope.details = function(item) {
      $scope.itemss = {
        OrderNum : item.OrderNum
      };
      $mdDialog.show({
        controller: detailsController,
        templateUrl: 'views/accessSystem/auditDetails/add.html',
      });
    };

    function detailsController($scope, $mdDialog) {
      failureTransactionAuditRecordsService.detailsQuery($scope.itemss,function(res){
          $scope.datas = res.data;
      });
      /**
       *  取消弹出框方法
       */
      $scope.hideaa = function() {
        $mdDialog.hide();
      };
    }

    //监听表单,当表单有错时,禁止查询
    $scope.$watch('myForm.$invalid', function(newValue) {
      newValue ? $scope.flag.arrow = false : $scope.flag.arrow = true;
    });
  }
   failureTnAtRsController.$inject = ['$scope','$mdDialog','failureTransactionAuditRecordsService','CoreService','CoreLoading'];
})();